﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace CrashSimul8or
{
    public class Particle
    {
        public Texture2D Texture { get; set; }
        public Vector2 Position { get; set; }
        public Vector2 Velocity { get; set; }
        public float Angle { get; set; }
        public float AngularVelocity { get; set; }
        public Color Color { get; set; }
        public float Size { get; set; }
        public int LifeTime { get; set; }
        public int TTL { get; set; }

        /// <summary>
        /// Smiður fyrir eina Particle.
        /// </summary>
        /// <param name="texture">Texture fyrir particle-ið</param>
        /// <param name="position">Staðsetning</param>
        /// <param name="velocity">Hraði</param>
        /// <param name="angle">Snúnings horn</param>
        /// <param name="angularVelocity">Snúnings hraði</param>
        /// <param name="color">Litur</param>
        /// <param name="size">Stærð</param>
        /// <param name="ttl">Niðurtalning til dauða (Time To Live)</param>
        public Particle(Texture2D texture, Vector2 position, Vector2 velocity,
            float angle, float angularVelocity, Color color, float size, int ttl)
        {
            Texture = texture;
            Position = position;
            Velocity = velocity;
            Angle = angle;
            AngularVelocity = angularVelocity;
            Color = color;
            Size = size;
            TTL = ttl;
            LifeTime = TTL;
        }

        /// <summary>
        /// Fall sem færir Particle, snýr því og lækkar
        /// tímann sem hún á eftir að lifa.
        /// </summary>
        public virtual void Update()
        {
            TTL--;
            Position += Velocity;
            Angle += AngularVelocity;
        }

        /// <summary>
        /// Einfalt fall sem teiknar eitt particle
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch til að teikna</param>
        /// <param name="cameraPos">Staðsetning myndavélar</param>
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            Rectangle sourceRectangle = new Rectangle(0, 0, Texture.Width, Texture.Height);
            Vector2 origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            spriteBatch.Draw(Texture, Position, sourceRectangle, Color,
                Angle, origin, Size, SpriteEffects.None, 0f);
        }
    }
}
